<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of TranhDAO
 *
 * @author HOANGPHUC
 */
require ("../ENTITY/Tranh.php");
class TranhDAO {

    public function __construct() {
        require ("../UTIL/MySQLProvider.php");

    }

    public static  function Create($column, $value) {

        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Insert("tranh", $column, $value);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function Edit($column, $value, $whereColumn, $whereValue) {
        //require ("/UTIL/MySQLProvider.php");
        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Update("tranh", $column, $value, "ID", $whereValue);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function Remove($whereColumn, $whereValue) {
        // require ("/UTIL/MySQLProvider.php");
        $dbHandle = new MySQLProvider();
        $flag = $dbHandle->Delete("tranh", "ID", $whereValue);
        $dbHandle->CloseConnection();
        return $flag;
    }

    public static function findAll() {
        // require ("/UTIL/MySQLProvider.php");

        $dbHandle = new MySQLProvider();
        $result = $dbHandle->GetResultSet("select * from Tranh");
        $arr = array();
        $i = 0;

        while ($r = mysql_fetch_array($result)) {

            $tr = new Tranh();
            $tr->SetId($r['ID']);
            $tr->SetTen($r['TEN']);
            $tr->SetSoLuongTon($r['SOLUONGTON']);
            $tr->SetDonGia($r['DONGIA']);
            $tr->SetSoLuongBan($r['SOLUONGBAN']);
            $tr->SetMoTa($r['MOTA']);
            $tr->SetTheLoai($r['MATHELOAI']);
            $tr->SetTenEn($r['TEN_EN']);
            $tr->SetDonGiaUSD($r['DONGIA_US']);
            $tr->SetMoTaEn($r['MOTA_EN']);
            $tr->SetURL($r['URL']);
            $arr[$i] = $tr;
            $i++;
        }
        $dbHandle->CloseConnection();
        return $arr;
    }

    public static function findByName($name) {
        $dbHandle = new MySQLProvider();
        $result = $dbHandle->GetResultSet("select * from tranh where ten like '%" . $name . "%' or Ten_En like '%" . $name . "%'");
        $arr = array();
        $i = 0;

        while ($r = mysql_fetch_array($result)) {

            $tr = new Tranh();
            $tr->SetId($r['ID']);
            $tr->SetTen($r['TEN']);
            $tr->SetSoLuongTon($r['SOLUONGTON']);
            $tr->SetDonGia($r['DONGIA']);
            $tr->SetSoLuongBan($r['SOLUONGBAN']);
            $tr->SetMoTa($r['MOTA']);
            $tr->SetTheLoai($r['MATHELOAI']);
            $tr->SetTenEn($r['TEN_EN']);
            $tr->SetDonGiaUSD($r['DONGIA_US']);
            $tr->SetMoTaEn($r['MOTA_EN']);
            $tr->SetURL($r['URL']);
            $arr[$i] = $tr;
            $i++;
        }
        $dbHandle->CloseConnection();
        return $arr;
    }
    public static function findbyid($id)
    {
        $dbHandle = new MySQLProvider();
        $result = $dbHandle->GetResultSet("select * from tranh where id='$id'");
        $arr = array();
        $i = 0;

        while ($r = mysql_fetch_array($result)) {

            $tr = new Tranh();
            $tr->SetId($r['ID']);
            $tr->SetTen($r['TEN']);
            $tr->SetSoLuongTon($r['SOLUONGTON']);
            $tr->SetDonGia($r['DONGIA']);
            $tr->SetSoLuongBan($r['SOLUONGBAN']);
            $tr->SetMoTa($r['MOTA']);
            $tr->SetTheLoai($r['MATHELOAI']);
            $tr->SetTenEn($r['TEN_EN']);
            $tr->SetDonGiaUSD($r['DONGIA_US']);
            $tr->SetMoTaEn($r['MOTA_EN']);
            $tr->SetURL($r['URL']);
            $arr[$i] = $tr;
            $i++;
        }
        $dbHandle->CloseConnection();
        return $arr;
    }

}

?>
